-
-
Notifications
You must be signed in to change notification settings - Fork 416
Add prefer-class-fields
rule
#2512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add prefer-class-fields
rule
#2512
Conversation
What should we do if the assignment is unreachable? class Foo {
constructor(x) {
if (x) {return}
this.foo = 'foo';
}
} |
It's dynamically set, so it cannot be statically defined. It should not be reported by this rule. |
Hey @fregante! Or maybe we can just agree that once the work in this PR is done you'll maybe just run your linter on it once? |
Handled stopping of the static analysis on unsupported case: 3376845 |
Okay, I fixed all test/linting errors connected with my rule - should I fix other as well? They seems to be connected with some default options missing in already existing rules? |
Hey! I've merged last changes from main to the branch of this PR - now it's ready to be reviewed again |
Change the test file extension from |
@sindresorhus done: 8358a43 I'm not sure yet why the tests are failing - locally they're working just fine. |
Okay, got it working and all of the requested changes are applied. BTW it's weird, but for me the |
ready to be re-reviewed @fisker |
rules/prefer-class-fields.js
Outdated
const validConstructorProperties | ||
= firstInvalidProperty === -1 | ||
? constructorBody | ||
: constructorBody.slice(0, firstInvalidProperty); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already use a loop, we can use the index directly, no need slice here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, changed implementation to set index
variable for initial loop iteration: 93010be
@FRSgit Bump :) |
Fixed the fix logic for some edge cases, especially class Foo {
constructor() {
this.bar = 1;
}
static} |
Adds
prefer-class-fields
rule which turns:into:
Fixes #314
IssueHunt Summary
Referenced issues
This pull request has been submitted to:
prefer-class-fields